package com.qf.aop2204.controller;

import com.qf.aop2204.vo.UserVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.misc.Regexp;

import javax.validation.Valid;
import javax.validation.constraints.*;

@RestController
@RequestMapping("/param")
@Validated //开启参数校验功能
public class ParamController {
    @GetMapping("/login")
    public String login(@NotNull @Size(min=5,max=10) String name, @NotEmpty(message = "不能是空串") String password,
                        @Email String email ,@Pattern(regexp = "138.*") String phone) throws Exception {
//        if (name ==null){
//            throw new Exception("用户名为空");
//        }
//        if (name.length()<5||name.length()>10){
//            throw new Exception("用户名错误");
//        }
        return "login success";
    }
    @PostMapping("/regist")
    public String regist(@Valid UserVo user){//如果对象收参校验功能

        return "regist success";
    }
}
